const XLSX = require('xlsx')
const getData = (filePath)=>{
    const workBook = XLSX.readFile(filePath)
    for (let sheetsKey in workBook.Sheets) {
        const sheet = workBook.Sheets[sheetsKey];
        // console.log(json)
        //只处理第一个工作簿
        return XLSX.utils.sheet_to_json(sheet)
    }
}

const saveRes = (json,path)=>{
    const workBook = XLSX.utils.book_new()
    const workSheet = XLSX.utils.json_to_sheet(json);
    XLSX.utils.book_append_sheet(workBook, workSheet)
    XLSX.writeFile(workBook,path,{
        bookType: 'xlsx'
    })
}

module.exports = {
    getData,
    saveRes
}
